package com.inossem.utils.base;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by leij on 2017/6/28.
 */

public class RegexUtils {

    private static final String REGEX_NUMBER = "^[1-9]\\d*$";//正整数

    private static final String REGEX_DECIMAL = "^0(\\.\\d+)?$|^[1-9]\\d*(\\.\\d+)?$";//正整数和正小数

    private static final String REGEX_ZERO = "^0+(\\.?0+)?$";//各种0,如：0,0.0,00,000

    private static boolean check(String regex, String message) {
        Pattern p = Pattern
                .compile(regex);
        Matcher m = p.matcher(message);
        return m.matches();
    }

    public static boolean checkZero(String message) {
        if (TextUtils.isEmpty(message)) {
            return false;
        }
        return check(REGEX_ZERO, message);
    }

    public static boolean checkNumber(String message) {
        if (TextUtils.isEmpty(message)) {
            return false;
        }
        return check(REGEX_NUMBER, message);
    }

    public static boolean checkDecimal(String message) {
        if (TextUtils.isEmpty(message)) {
            return false;
        }
        return check(REGEX_DECIMAL, message);
    }

}
